package com.supermap.dataservice.agrinfo.dao;

import com.supermap.dubbo.api.agrinfo.entity.Agrpraise;
import org.apache.ibatis.annotations.*;

/**
 * @author lxs
 * @Title:点赞数据访问层
 * @Description:
 * @date 2018/3/8  16:40
 */
@Mapper
public interface AgrpraiseDao {
    /**
     * 根据农情ID得到对应的农情点赞数
     * @param agrInfoId
     * @return
     */
    @Select("select COUNT(*) from t_agrpraise where agrInfoId=#{agrInfoId}")
    int getAgrpraiseCount(@Param("agrInfoId") int agrInfoId);

    /**
     * 根据农情ID和该用户ID得到对应的农情是否有对应的点赞数据
     * @param userId
     * @param agrInfoId
     * @return
     */
    @Select("select isPraise from t_agrpraise  where userId=#{userId} and agrInfoId=#{agrInfoId}")
   String  getPraise(@Param("userId") int userId, @Param("agrInfoId") int agrInfoId);

    @Delete("delete from t_agrpraise where  userId=#{userId} and agrInfoId=#{agrInfoId}")
    int delAgrById(@Param("userId") int userId, @Param("agrInfoId") int agrInfoId);

    /**
     * 点击赞 增加一条数据
     * @param agrpraise
     * @return
     */
    @Insert("Insert into t_agrpraise(agrInfoId,isPraise,userId) "+"values(#{agrpraise.agrInfoId},#{agrpraise.isPraise},#{agrpraise.userId}"+")")
    int addAgrpraise(@Param("agrpraise") Agrpraise agrpraise);

}
